#include <iostream>
using namespace std;

int modpow(int a, int b, int c) {
	int ret = 1;
	int tmp = a;
	while (b) {
		if (b&1) ret=ret*tmp%c;
		tmp=tmp*tmp%c;
		b>>=1;
	}
	return ret;
}

int main() {
	int a, b, c, r;
	cin >> a >> b >> c;
	r = modpow(a, b, c);
	cout << r << endl;
	return 0;
}
